<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
     
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>启动页</title>
	<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="bootstrap-table/dist/bootstrap-table.css">
    <link rel="stylesheet" type="text/css" href="css/xcConfirm.css" />
	<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
	<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
	<link rel="stylesheet" href="bootstrap-fileinput-master/css/fileinput.min.css">
    
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    
    <style type="text/css">
        #panel {
            position: absolute;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        .td1{
			float:left;
			width:50px;
			display: block; 
			valign:middle;
		}
		.td2{
			float:left;
			width:200px;
			display: block; 
			valign:middle;
		}
		.td3{
			float:left;
			width:660px;
			display: block; 
			valign:middle;
		}
    </style>
</head>
<body>
	<div class="x-body">
            <div   class="form-horizontal" role="form">
            
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">启动页:</label>
			    <span style="color: red">仅支持JPG、PNG、JPEG、BMP格式，文件小于1M</span>
			    <div class="col-sm-3">
			    	<input id="upload"  type="file" name="file" multiple class="file-loading">
					<input id="picture" name="picture" type="hidden" value="${page.gImg}">
					<input id="id" name="id" type="hidden" value="${page.gId}">
			    </div>
			  </div>
		     <div class="form-group" style="padding-left: 30%">
		        <button type="submit"   onclick="save()"  class="btn btn-info" >保存</button>
		     </div>
          </div>
	</div>
        <script src="lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="js/x-layui.js" charset="utf-8">
        </script>
        <!-- 加载需要的js -->
		<script src="js/jquery-3.2.1.min.js"></script>
		<script src="js/common2.js"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="js/jquery-bootstrap-pagination.js"></script>
		<script src="js/qunit-1.11.0.js"></script>
		<script src="js/bootstrap-datetimepicker.js"></script>
		<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	    <script src="js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
	    <script src="bootstrap-fileinput-master/js/fileinput.min.js"></script>
		<script src="bootstrap-fileinput-master/js/locales/zh.js"></script>
        <script>
	        layui.use(['form','layer','upload'], function(){
	            $ = layui.jquery;
	          var form = layui.form()
	          ,layer = layui.layer;
	          });
        
	        $("#upload").fileinput({
	    	    uploadUrl: "upload/photoImg",
	    	    uploadAsync: true,
	    	    maxFileCount: 1,
	    	    initialPreview: [ 
	    	    	'<img src="${page.gImg}"  id="img"  class="file-preview-image"  width="256px" height="160px" />',
	    	    ],
	    	}).on('fileuploaded', function(event, data, previewId, index) {
	    	    var form = data.form, files = data.files, extra = data.extra,
	            response = data.response, reader = data.reader;
	    		if(response.data != null && response.data != ""){
	    	    	$("#picture").val(response.data);			
	    		}else{
	    			alert("图片服务器异常，请重新上传！");
	    		}
	    	});
    	
    		function save() {
    			var gId = $("#id").val();
    			var picture =	$("#picture").val();
      		   	 if(picture == null||picture=="") {
      		   		layer.msg('图片不能为空!',{icon:2,time:2000});
      				  return ;
      		   	 }
    			 var  data = {"gId":gId,"gImg":picture,"gType":"2"}
    	         console.log(data);
    	         $.ajax({
    	             type: "post",
    	             url: "advert/addOrUpdate",
    	             data: JSON.stringify(data),
    	             contentType:"application/json;charset=UTF-8", 
    	             dataType:"json",
    	             success: function(data){    
    	           	 if(data.code==200){
    	           		layer.msg(data.msg,{icon:1,time:4000});		
    	           		setTimeout("cancel()",1000);
    				} else {
    						var txt = data.msg;
    						window.wxc.xcConfirm(txt,
    								window.wxc.xcConfirm.typeEnum.info);
    					}
    				}
    			});
    		}
    		
    		function cancel() {
    			window.location.href = "advert/getBootPage";
    		}
    		
        </script>
</body>
</html>